//模拟实现BlockingQueue
class MyBlockingQueue {
    //第一步先实现一个队列
    private static int[] items = new int[1000];
    private int head = 0;
    private int cur = 0;
    private int size = 0;
    //使用synchronized加锁保证线程安全
    synchronized public void put(int value) throws InterruptedException {
        while(size == items.length) {

            this.wait();
        }
        items[cur] = value;
        cur++;
        if(cur == items.length) {
            cur = 0;
        }
        size++;
        this.notify();
    }
    //使用wait和notify来进行阻塞
    synchronized  public Integer take() throws InterruptedException {
        while(size == 0) {
            this.wait();
        }
        int value = items[head];
        head++;
        if(head == items.length) {
            head = 0;
        }
        size--;
        this.notify();
        return value;

    }
}



public class ThreadDemo15 {
    public static void main(String[] args) {

    }
}
